﻿using MediatR;
using ClientBasicData.Api.Application.Command;
using ClientBasicData.Domain.Client;
using ClientBasicData.ErrorCode;
using ClientBasicData.Infrastructure.Interface;

namespace ClientBasicData.Api.Application.Handler
{
    /// <summary>
    /// 客户下拉框命令处理器
    /// </summary>
    public class GetClientDropdownCommandHandler : IRequestHandler<GetClientDropdownCommand, ApiResult<List<ClientModel>>>
    {
        private readonly IBaseRespository<ClientModel> _clientRepo;

        public GetClientDropdownCommandHandler(IBaseRespository<ClientModel> clientRepo)
        {
            _clientRepo = clientRepo;
        }

        public Task<ApiResult<List<ClientModel>>> Handle(GetClientDropdownCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<List<ClientModel>>()
            {
                Code = ApiEnum.Success,
                Msg = "客户查询成功"
            };
            var clients = _clientRepo.GetAll().Where(x => !x.Isdel).ToList();

            result.Data = clients;

            return Task.FromResult(result);
        }
    }
}